﻿//************************************************************************************************
// Copyright © 2014 Steven M. Cohn. All Rights Reserved.
// 
//************************************************************************************************

namespace River.Folderize.UI
{
	using System;
	using System.Windows;
	using System.Windows.Controls;
	using System.Windows.Media.Imaging;


	public class ImageButton : Button
	{
		static ImageButton ()
		{
			DefaultStyleKeyProperty.OverrideMetadata(
				typeof(ImageButton),
				new FrameworkPropertyMetadata(typeof(ImageButton)));
		}


		public static readonly DependencyProperty BorderVisibilityProperty =
			DependencyProperty.Register("BorderVisibility", typeof(Visibility), typeof(ImageButton),
			new FrameworkPropertyMetadata(Visibility.Hidden, FrameworkPropertyMetadataOptions.AffectsRender));

	
		public static readonly DependencyProperty DisabledImageProperty =
			DependencyProperty.Register("DisabledImage", typeof(BitmapImage), typeof(ImageButton));

	
		public static readonly DependencyProperty HoverImageProperty =
			DependencyProperty.Register("HoverImage", typeof(BitmapImage), typeof(ImageButton));

	
		public static readonly DependencyProperty ImageSizeProperty =
			DependencyProperty.Register("ImageSize", typeof(double), typeof(ImageButton));


		public static readonly DependencyProperty NormalImageProperty =
			DependencyProperty.Register("NormalImage", typeof(BitmapImage), typeof(ImageButton));


		public static readonly DependencyProperty PressedImageProperty =
			DependencyProperty.Register("PressedImage", typeof(BitmapImage), typeof(ImageButton));
			//new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender, ImageSourceChanged));


		public Visibility BorderVisibility
		{
			get { return (Visibility)GetValue(BorderVisibilityProperty); }
			set { SetValue(BorderVisibilityProperty, value); }
		}


		public BitmapImage DisabledImage
		{
			get { return (BitmapImage)GetValue(DisabledImageProperty); }
			set { SetValue(DisabledImageProperty, value); }
		}


		public BitmapImage HoverImage
		{
			get { return (BitmapImage)GetValue(HoverImageProperty); }
			set { SetValue(HoverImageProperty, value); }
		}

	
		public double ImageSize
		{
			get { return (double)GetValue(ImageSizeProperty); }
			set { SetValue(ImageSizeProperty, value); }
		}


		private static void ImageSourceChanged (
			DependencyObject sender, DependencyPropertyChangedEventArgs e)
		{
			Application.GetResourceStream(new Uri("pack://application:,,," + (string)e.NewValue));
		}
		
		
		public BitmapImage NormalImage
		{
			get { return (BitmapImage)GetValue(NormalImageProperty); }
			set { SetValue(NormalImageProperty, value); }
		}


		public BitmapImage PressedImage
		{
			get { return (BitmapImage)GetValue(PressedImageProperty); }
			set { SetValue(PressedImageProperty, value); }
		}
	}
}